<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../../js/react.development.js"></script>
    <!-- 用于支持react操作DOM -->
    <script type="text/javascript" src="../../js/react-dom.development.js"></script>
    <!-- 用于将jsx转为js -->
    <script type="text/javascript" src="../../js/babel.min.js"></script>
    <!-- 用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="../../js/prop-types.js"></script>
</head>
<body>
    <div id="test"></div>

    <script type="text/babel">
        class MyComponent extends React.Component{
            state = {}
            static propTypes = {}
            static defaultTypes = {}
            myRef = React.createRef()
            myRef2 = React.createRef()
            render(){
                return (
                    <div>
                        <input ref={this.myRef} type="text" placeholder="点击按钮提示数据"/>
                        <button onClick={this.show}>提示左输入框数据</button>
                        <input ref={this.myRef2} onBlur={this.show2} type="text" placeholder="失去焦点提示数据"/>
                    </div>
                )
            }
            show = ()=>{
                console.log("1: ",this.myRef);
                const {current}= this.myRef
                alert(current.value)
            }
            show2 = ()=>{
                console.log("2: ",this.myRef2);
                const {current}= this.myRef2
                alert(current.value)
            }
        }
        
        let p ={}
        ReactDOM.render(<MyComponent {...p}/>,document.getElementById("test"))
    </script>
</body>
<style>
</style>
</html>